<!--
/**************************************************
* @(#)organizationadd.jsp
*
* Copyright (c) 2005 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2005/2/14, owen xia
*  1) first release
   2) add javascript method changelist2,implemnt select jump
/**************************************************
-->
<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>新增订货单位常用联系方式</title>
<%@ include file="../common.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=root%>/css/caigouxitong.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/hi-check.js"></SCRIPT>

<%
HashMap tMap = (HashMap)request.getAttribute("Organization2");
if(tMap != null){
    System.out.println(""+tMap.size());
}else{
    System.out.println("false");
}

String exceptiondesc = (String)request.getAttribute("exception_desc");
%>
<%
if(message==null){        
if(exceptiondesc!=null){
        out.println("<script>");
        out.println("alert('"+exceptiondesc+"')");
        out.println("</script>");
        }
%>
<script>
	 var addLineStr = "&nbsp;&nbsp;"
					+ "<INPUT id=idItem type=text name=gs_deliver_goods_addr maxlength=50 size=60/><FONT color=red>&nbsp;*</FONT>"
					+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
					+ "<INPUT id=idItem type=text name=gs_order_contact_name maxlength=50 size=20/>"
					+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
					+ "<INPUT id=idItem type=text name=gs_order_contact_phone maxlength=50 size=20/><BR>";
					
  function change1(optval)
  {
  		var val = optval;
		if(val=='0')
		{
			var listbox = document.getElementById("manuftype2");
			listbox.length = 0;
			var option = new Option();
			option.text = "---二级---";
			option.value = "0";			
			listbox.options[listbox.length] = option;

		}
		else
		{
	  	<%
	  		if(tMap !=null)
	  		{
		 	   	Collection tCollection = tMap.keySet();
		        Iterator tIterator = tCollection.iterator();
	  		       while(tIterator.hasNext())
	  		       {
	  		           String tKey = (String)tIterator.next();
	  		           ArrayList tList = (ArrayList)tMap.get(tKey);
	  	%>
		  				if(val == '<%=tKey%>')
		  				{
			  				var counter;
			  				var listbox = document.getElementById("manuftype2");
			  				listbox.length = 0;  		  	  	
									var option = new Option();
									option.value = "0";
									option.text = "---二级---";
									listbox.options[listbox.length] = option;			  											
			<%					
								for(int n=0;n<tList.size();n++)
								{
								    GSOrganizationBean tGSOrganizationBean = (GSOrganizationBean)tList.get(n);
								    String categoryId = tGSOrganizationBean.getGs_org_id();
								    String categoryName = tGSOrganizationBean.getGs_org_name();
			%>				
									var temp1 = '<%=categoryId%>';
									var temp2 = '<%=categoryName%>|<%=categoryId%>';
									var option = new Option();
									option.value = temp1;
									option.text = temp2;
									listbox.options[listbox.length] = option;						
			<%
								}
			%>
		  				}
	  	<%
	  		    	}
	  		       
	  		}
	  	%>
	  	}	
	}	
   //返回
   function back()
   {
    	//checkform.action='<%=root%>/A400801.do';
    	//checkform.submit();
    	self.close();
   }
 
		
   function check()
   { 
  	
  	    if(document.checkform.gs_org_id.value=="0")
  	    {
  	     	//alert(document.checkform.gs_org_id.value)
  	     	alert("组织机构编号不能为空！");
	     	return false;
  	    }
  	    var itemName="gs_deliver_goods_addr";
        var items=document.getElementsByName(itemName);
        for(var i=0;i<items.length;i++)
        {
              var item=items[i];
              //alert(item.value);
              if(item.value=="")
              {
                alert("送货地址不能为空！");
	            return false;
              }     
         }  	    
  	   
		 //checkform.action="<%= response.encodeURL(request.getContextPath() + "/A400804.do") %>";   
		 //document.checkform.submit();
		 //window.close();
		 
		 var gs_deliver_goods_addr = document.getElementsByName("gs_deliver_goods_addr");
		 var addr = new Array();
		 var gs_order_contact_name = document.getElementsByName("gs_order_contact_name");
		 var name = new Array();
		 var gs_order_contact_phone = document.getElementsByName("gs_order_contact_phone");
		 var phone = new Array();
		 for(i=0;i<gs_deliver_goods_addr.length;i++)
		 {
		 	addr[i] = gs_deliver_goods_addr[i].value;
		 }
		 for(i=0;i<gs_order_contact_name.length;i++)
		 {
		 	name[i]= gs_order_contact_name[i].value;
		 }
		 for(i=0;i<gs_order_contact_phone.length;i++)
		 {
		 	phone[i]= gs_order_contact_phone[i].value;
		 }
		 var manuftype1 = document.getElementById("manuftype1").value;
		 var manuftype2 = document.getElementById("manuftype2").value;
		 var arrayR = new Array();
		 arrayR[0] = addr;
		 arrayR[1] = name;
		 arrayR[2] = phone;
		 arrayR[3] = manuftype1;
		 arrayR[4] = manuftype2;
		 window.returnValue = arrayR;
		 window.close();
	}
	
	
	var MaxLineCount=30;
	var Counter=1;
	var Num;
	function DoNextLine(lineHtml)
	{  
	   if(Counter>=MaxLineCount)
	   {
	     	alert("订货单位常用联系方式不能超过"+MaxLineCount+"个");
	     	return;
	   }
	   
	   // add by Jackey start
	   
	   //old
	   //document.getElementById("idLines").innerHTML+=lineHtml;
	   
	   var addStr = "<DIV id=" + Counter + ">" + addLineStr + "</DIV>";
	   
	   //new
	   document.getElementById("idLines").innerHTML += addStr;
	   
	   // add by Jackey end
	   
	   Counter++;
	}

		
	function DoRemoveLine(lineHtml)
    {
    	//old
    	/*
        //alert("Counter:"+Counter);
        if(Counter>1)
        {
          	DoRemoveLineByIndex(lineHtml,--Counter);
        }
        else
        {
          	DoRemoveLineByIndex(lineHtml,1);              
        }
        */
        
        
        //new 
        if(Counter>1)
        {
          	DoRemoveLineByIndex(addLineStr,--Counter);
        }
        else
        {
          	DoRemoveLineByIndex(addLineStr,1);              
        }
        
          
     }
		   
    
     function DoRemoveLineByIndex(lineHtml,index)
     {
        if(index==1)
        {
            document.getElementById("idLines").innerHTML = "";
        }
		else
		{
			lastLine=lineHtml.replace("index",""+index);            		   
			orginalHTML=document.getElementById("idLines").innerHTML;
			//var resultHTML=orginalHTML.replace(lastLine,"");
			var idLine = document.getElementById("line").innerHTML;
			
			var subStr = "";
			subStr  = "<DIV id=" + Counter + ">";
			subStr += document.getElementById(Counter).innerHTML; 
			subStr += "</DIV>";
			
			var resultHTML = orginalHTML.substr(0,orginalHTML.length - subStr.length);
			document.getElementById("idLines").innerHTML=resultHTML;
			if(orginalHTML.length<resultHTML.length)
			{
			   --Counter;
			}
			else
			{
			     		   		   		       
			}
		}   
	 }
</script>

</head>
<body BGCOLOR="#f2f2f2" text="#000000" leftmargin="0" topmargin="0"  marginwidth="0" marginheight="0">
<p><br>
</p>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td height="20">
		<table width="100%" border="0" cellspacing="0" cellpadding="1">
			<tr height="20">
				<td height="20" width="1" class="mtxt_black">&nbsp;</td>
				<td height="30" width="758" class="mtxt_black">新增订货单位常用联系方式</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="bg_line" height="2"></td>
	</tr>
</table>

<br>

<!--订货单位常用联系方式--------------------------------------------------------------------------------------------------------------------------->
<form name="checkform" action="A400804.do" method="post">



<table width="90%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td>
		
		<table class=bg_table id=tableId cellspacing=1 cellpadding=0
			style="padding-left:5;padding-right:5" width=100% align=center
			border=0>
			<TR class="bg_column">
				<TD colspan="4">订货单位常用联系方式</TD>
			</TR>
			<TR class="bg_row_odd" >
				<TD align=center width="20%">订货单位编号</TD>
				<TD align=center width="25%">
				  <select id="manuftype1" name="manuftype1" onChange="change1(this.value)">
				  <option value="0">---一级---</option>
				  
		    <%//获取所有机构代码
			 ArrayList tOraganization = (ArrayList) request.getAttribute("Oraganization");
		     String tManufType1 = request.getParameter("manuftype1");
		     GSOrganizationBean tGSOrganizationBean = null;
			 if (tOraganization != null) {
				for (int n = 0; n < tOraganization.size(); n++) {
				    tGSOrganizationBean = (GSOrganizationBean) tOraganization.get(n);

					%>
					<option value="<%=tGSOrganizationBean.getGs_org_id() %>">
						<%=tGSOrganizationBean.getGs_org_name()%>|<%=tGSOrganizationBean.getGs_org_id() %>
					</option>
					<%}
			}
			%>
				</select>
				
				<font color='red'>&nbsp;*</font>
				</TD>
				<TD align=center>
				
				<select id="manuftype2" name="gs_org_id">	
						<option value="0">---二级---</option>				
						<%
							String tManufType2 = request.getParameter("gs_org_id");
						    
							if(tManufType1 != null && !tManufType1.equals("0")){
							    //int tIntManuType2 = Integer.parseInt(tManufType2);
							    ArrayList temp = (ArrayList)tMap.get(tManufType1);
							    if(temp!= null && temp.size() > 0){
									for(int i=0; i<temp.size(); i++){
									    GSOrganizationBean tGSManuf2 = (GSOrganizationBean)temp.get(i);
									    if(tManufType2 != null && tManufType2.equals(tGSManuf2.getGs_org_id())){
							%>
									<option value="<%=tManufType2%>" selected><%=tGSManuf2.getGs_org_name()%>|<%=tGSManuf2.getGs_org_id()%></option>
							<%			        
									    }else{
							%>
									<option value="<%=tGSManuf2.getGs_org_id()%>"><%=tGSManuf2.getGs_org_name()%>|<%=tGSManuf2.getGs_org_id()%></option>
									
							<%			}	
									}
							    }
							}
						%>

						</select>
						<font color='red'>&nbsp;*</font>
				</TD>
				<TD align=center>
				 <input type="button" class="kuang" name="增加地址" value="增加地址" onclick="DoNextLine(document.getElementById('line').innerHTML);">
				 
				 <input type="button" class="kuang" name="删除地址" value="删除地址" onclick="DoRemoveLine(document.getElementById('line').innerHTML);">
				</TD>
				
			</TR>
			<TR class="bg_row_odd" >
				<TD align=center colspan="2">送货地址</TD>
				<TD align=center>订货联系人姓名</TD>
				<TD align=center>订货联系电话</TD>
			</TR>
			
		
			<TR class="bg_row_odd"  >
			   <TD colspan="4">
				<div id="line"><script>document.write(addLineStr);</script></div>
		        <div id="idLines"></div>
				
                </TD>
			
			</TR>
			
		
		</TABLE>
		</td>
	</tr>
	
</table>

</form>

<!----------------------------------------------------------------------------------------------------------------------------------->
<p align="center">
<input type="button" class="kuang" value="增加" onclick="return check();"> 
<input type="button" class="kuang" value="关闭" onclick="return back();"></p>
<p>
<p>
<p>
<p><br>
<br>
<br>
<br>
<br>

</body>
<%} 
%>
</html>
